package org.imsetal.iluserservice.controller;

import jakarta.annotation.Resource;
import org.imsetal.ilapi.utils.Result;
import org.imsetal.iluserservice.pojo.User;
import org.imsetal.iluserservice.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("userInfo")
public class UserInfoController {
    @Resource
    UserService userService;

    @GetMapping("")
    public Result getUserInfo(@RequestParam String token) {
        String username=userService.getUsernameByToken(token);
        User user = userService.getUserInfo(username);
        if(user == null) {
            return Result.error("300","没有找到该用户");
        }else{
            return Result.success(user);
        }
    }

    @GetMapping("checkUserExist")
    public Result checkUserExist(@RequestParam Long userid) {
        return Result.success(userService.checkUserExist(userid));
    }
}
